<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Z-7
  Date: 2022/3/3
  Time: 17:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="${pageContext.request.contextPath}/resource/bootstrap4/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/jquery-3.2.1.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/resource/bootstrap-treeview/js/bootstrap-treeview.js"></script>
    <script src="${pageContext.request.contextPath}/resource/bootstrap4/js/bootstrap.js"></script>
    <title>购物车详情</title>
</head>
<body>
<jsp:include page="../head.jsp"/>
<div class="container">
    <form action="/carts/detail" method="post"><input type="hidden" name="pageNum" value="${page.pageNum}"></form>
    <table class="table table-hover">
        <thead>
        <tr>
            <th scope="col">编号</th>
            <th scope="col">商品名称</th>
            <th scope="col">数量</th>
            <th scope="col">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${page.list}" var="cart" varStatus="count">
            <tr>
                <th scope="row">${count.count}<input type="checkbox" name="ids" value="${cart.id}"></th>
                <td>${cart.goodsName}</td>
                <td>${cart.buyNum}</td>
                <td>
                    <button type="button" class="btn btn-outline-danger">删除</button>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="100">
                <button type="button" class="btn btn-primary" onclick="addOrder()">下单</button>
            </td>
        </tr>
        </tbody>
    </table>
    <jsp:include page="/resource/page/pages3.jsp"/>
</div>
<script type="text/javascript">
    function addOrder() {
        var str = "";
        $(":checkbox").each(function () {
            if(this.checked){
                str += $(this).val();
            }
        });
        if(str == ""){
            alert("请至少选择一个订单");
            return;
        }
        location="${pageContext.request.contextPath}/order/creatOrder?"+$('[name="ids"]').serialize();
    }
</script>
</body>
</html>
